//===============================================================================
// Microsoft patterns & practices
// Guidance Explorer Offline Client
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================



using System.Windows.Forms;

namespace GuidanceExplorer.Model
{
    public enum FieldType { Combo, Text , Check}

    public class Field
    {
        /// <summary>
        /// Factory.
        /// </summary>
        /// <returns></returns>
        public static Field New()
        {
            return new Field();
        }

        /// <summary>
        /// Factory creates a copy from an online field
        /// </summary>
        /// <param name="onlineField"></param>
        /// <returns></returns>
        public static Field New(OnlineGuidance.Field onlineField)
        {
            Field modelField = new Field();

            modelField.Name = onlineField.name;
            modelField.Visible = true;
            modelField.Caption = onlineField.name;
            modelField.DefaultSort = SortOrder.None;
            modelField.Distinct = false;
            modelField.Editable = true;
            modelField.ShowInGuidanceTypeNode = true;
            modelField.Type = FieldType.Text;
            modelField.Width = 100;

            return modelField;
        }

        /// <summary>
        /// The name of the field.
        /// </summary>
        private string _name;

        /// <summary>
        /// The caption of the field.
        /// </summary>
        private string _caption;

        /// <summary>
        /// The type of the field.
        /// </summary>
        private FieldType _type;

        /// <summary>
        /// Whether the combo sholuld display all the values in the library as options.
        /// </summary>
        private bool _distinct;

        /// <summary>
        /// The list of values available in the combo.
        /// </summary>
        private string[] _values;

        /// <summary>
        /// Whether the field is editable or not.
        /// </summary>
        private bool _editable = true;

        /// <summary>
        /// Column width
        /// </summary>
        private int _width = 100;

        /// <summary>
        /// The field's position in the list view
        /// </summary>
        private int _position = 0;

        /// <summary>
        /// Whether the field is visible or not
        /// </summary>
        private bool _visible = true;

        /// <summary>
        /// Whether the field is visible or not in the GuidanceType node
        /// </summary>
        private bool _showInTypeNode = true;

        /// <summary>
        /// The default sort order for this field
        /// </summary>
        private SortOrder _defaultSort;

        /// <summary>
        /// Default constructor.
        /// </summary>
        private Field()
        {
        }

        /// <summary>
        /// The name of the field.
        /// </summary>
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// The caption of the field.
        /// </summary>
        public string Caption
        {
            get { return _caption; }
            set { _caption = value; }
        }

        /// <summary>
        /// The type of the field.
        /// </summary>
        public FieldType Type
        {
            get { return _type; }
            set { _type = value; }
        }

        /// <summary>
        /// Whether the combo sholuld display all the values in the library as options.
        /// </summary>
        public bool Distinct
        {
            get { return _distinct; }
            set { _distinct = value; }
        }

        /// <summary>
        /// Whether the field is visible or not
        /// </summary>
        public bool Visible
        {
            get { return _visible; }
            set { _visible = value; }
        }

        public bool ShowInGuidanceTypeNode
        {
            get { return _showInTypeNode; }
            set { _showInTypeNode = value; }
        }

        /// <summary>
        /// The list of values available in the combo.
        /// </summary>
        public string[] Values
        {
            get { return _values; }
            set { _values = value; }
        }

        /// <summary>
        /// The column width
        /// </summary>
        public int Width
        {
            get { return _width; }
            set { _width = value; }
        }

        /// <summary>
        /// Whether the field is editable or not.
        /// </summary>
        public bool Editable
        {
            get { return _editable; }
            set { _editable = value; }
        }

        /// <summary>
        /// Get/set the field's position in the list view
        /// </summary>
        public int Position
        {
            get { return _position; }
            set { _position = value; }
        }

        /// <summary>
        /// The default sort order for this field
        /// </summary>
        public SortOrder DefaultSort
        {
            get { return _defaultSort; }
            set { _defaultSort = value; }
        }

        /// <summary>
        /// Returns a clone of the instance of the current Field
        /// </summary>
        /// <returns></returns>
        public Field Clone()
        {
            Field newField = new Field();
            newField.Caption = this.Caption;
            newField.Distinct = this.Distinct;
            newField.Editable = this.Editable;
            newField.Name = this.Name;
            newField.Position = this.Position;
            newField.ShowInGuidanceTypeNode = this.ShowInGuidanceTypeNode;
            newField.Type = this.Type;
            newField.Values = this.Values;
            newField.Visible = this.Visible;
            newField.Width = this.Width;
            newField._defaultSort = this._defaultSort;
            return newField;
        }
    }
}
